#-*-coding:utf-8-*-
# 两个栈组成队列
# key 一个栈的出栈作为另外一个栈的入栈元素
# min Stack
# key 用一个数来记录最小值，要在每次pop的时候刷新一下最小值


class CQueue(object):

	def __init__(self):
		self._stack1 = []
		self._stack2 = []

	def appendTail(self, value):
		"""
		:type value: int
		:rtype: None
		"""
		self._stack1.append(value)

	def deleteHead(self):
		"""
		:rtype: int
		"""
		if self._stack2:
			return self._stack2.pop()

		if not self._stack1:
			return -1

		while (self._stack1):
			self._stack2.append(self._stack1.pop())

		return self._stack2.pop()


class MinStack(object):

	def __init__(self):
		"""
		initialize your data structure here.
		"""
		self._sList = []
		self._minCount = -1

	def push(self, x):
		"""
		:type x: int
		:rtype: None
		"""
		self._sList.append(x)
		if self._minCount < 0:
			self._minCount = 0
		else:
			self._minCount = self._minCount if x >= self._sList[self._minCount] else len(self._sList) - 1

	def pop(self):
		"""
		:rtype: None
		"""
		if self._sList:
			popNum = self._sList.pop()
			self.refreshMinCount()
			return popNum
		return -1

	def top(self):
		"""
		:rtype: int
		"""
		if self._sList:
			return self._sList[-1]
		return -1

	def min(self):
		"""
		:rtype: int
		"""
		if self._sList and self._minCount >= 0:
			return self._sList[self._minCount]
		return -1

	def refreshMinCount(self):
		if len(self._sList) and self._minCount >= len(self._sList):
			minNum = self._sList[0]
			self._minCount = 0
			for idx, num in enumerate(self._sList):
				if num < minNum:
					self._minCount = idx
					minNum = num



if __name__ == '__main__':
	obj = CQueue()
	obj.appendTail(8)
	obj.appendTail(9)
	param_2 = obj.deleteHead()
	print param_2
	minStackObj = MinStack()
	minStackObj.push(3)
	minStackObj.push(-2)
	minStackObj.push(0)
	print minStackObj.min()
